﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ContribServices;

namespace AutoClick.WPFHelpers
{
    /// <summary>
    /// Logique d'interaction pour WPFAutoClickGauge.xaml
    /// </summary>
    public partial class WPFAutoClickGauge : Window
    {
        #region Variables
        private bool _autoClickNeeded;
        private System.Drawing.Point _gaugePosition;

        public bool AutoClickNeeded
        {
            get { return _autoClickNeeded; }
            set { _autoClickNeeded = value; }
        }
        #endregion

        #region Constructor
        public WPFAutoClickGauge(bool autoClickNeeded)
        {
            InitializeComponent();

            AutoClickNeeded = autoClickNeeded;
            //Set the vertical alignment of gauge
            this.Top = Screen.PrimaryScreen.Bounds.Height - this.Height;
        }
        #endregion

        #region Gauge interaction
        /// <summary>
        /// Method that sets the horizontal alignment of gauge according with the mouse's pointer
        /// </summary>
        /// <param name="onTop"></param>
        public void PlaceGauge(PointerDeviceEventArgs pointer)
        {
            _gaugePosition = new System.Drawing.Point((int)(Screen.PrimaryScreen.Bounds.Width - this.Width)
                , (int)(Screen.PrimaryScreen.Bounds.Height - this.Height));
            if (AutoClickNeeded)
            {
                if (pointer.X >= _gaugePosition.X && pointer.Y >= _gaugePosition.Y)
                    this.Left = 0;
                else
                    this.Left = _gaugePosition.X;
            }
        }
        /// <summary>
        /// Show the progress bar
        /// </summary>
        public void Start()
        {
            if (AutoClickNeeded)
                this.progressBar1.Visibility = System.Windows.Visibility.Visible;
        }
        /// <summary>
        /// Hide the progress bar
        /// </summary>
        public void Stop()
        {
            this.progressBar1.Visibility = System.Windows.Visibility.Collapsed;
        }
        #endregion
    }
}
